#ifndef TREE_H
#define TREE_H

#include <vector>
#include <map>
#include <string>
using namespace std;

// An itemorg of the tree, possibly an assembly or component(leaf)
class ItemOrg
{
public:
    ItemOrg(int itemId, int orgId ):
        mItemId(itemId), mOrgId(orgId),
        mIsTree(false), mIsSubTree(false),
        mIsCoProduct(false) {

    }

    void print(double usage = 1.0, string decStr = "", int depth = 0);

    void addComponent( ItemOrg* comp, double usage )
    {
        if( comp->isTree() )
        {
            comp->setSubTree(true);
        }
        mComponents.push_back(comp);
        mUsages.push_back(usage);
    }

    bool operator == (ItemOrg& a)
    {
        return ( a.itemId() == itemId() && a.orgId() == orgId() );
    }

    unsigned int key() const { return mKey; }
    void setKey( unsigned int v ) { mKey = v; }

    int itemId() const { return mItemId; }
    int orgId()  const { return mOrgId;  }
    void setItemId(int v) { mItemId = v; }
    void setOrgId(int v) { mOrgId = v; }

    bool isTree()const { return mIsTree; }
    void setTree(bool value) { mIsTree = value; }
    bool isSubTree() const { return mIsSubTree; }
    void setSubTree(bool value) { mIsSubTree = value; }

    bool isCoProduct() const { return mIsCoProduct; }
    void setCoProduct(bool value) { mIsCoProduct = value; }

    static unsigned int genKey(int &itemId, int &orgId )
    {
        return ( (unsigned int)(itemId & 0xffff)<<16 ) | (unsigned int)(orgId & 0xffff);
    }

private:
    int mItemId;
    int mOrgId;
    unsigned int mKey;

    bool mIsTree;
    bool mIsSubTree; //Is a sub tree of somebody - this case we don't need to print it
    bool mIsCoProduct;

    vector< ItemOrg* > mComponents;
    vector< double > mUsages;
};

#endif // TREE_H
